<template>
  <div class="login">
    <div class="login_box">
      <el-form>
        <!-- 账号密码 -->
        <el-form-item>
          <el-input
            v-model="username"
            placeholder="手机号或邮箱"
            prefix-icon="el-icon-user-solid"
          ></el-input>
          <el-input
            v-model="userpwd"
            placeholder="密码"
            type="password"
            prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <!-- 是否记住登录 -->
        <el-form-item>
          <el-checkbox-group v-model="Iscookie">
            <el-checkbox
              label="记住我"
              name="name"
            ></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <!-- 登录按钮 -->
        <el-form-item>
          <el-button
            type="primary"
            style="width:100%"
            round
            :loading="isloading"
            @click="Login"
          >登录</el-button>
        </el-form-item>
      </el-form>
      <div style="padding-top:30px">
        <el-divider class="divider">社交账号登录</el-divider>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      username: "",
      userpwd: "",
      Iscookie: "",
      isloading: false,
    };
  },
  methods: {
    Login() {
      let tel = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
      this.isloading = true;
      setTimeout(() => {
        if (this.username == "" && this.userpwd == "") {
          this.$message({
            message: "用户名、密码不能为空",
            type: "warning",
          });
        } else if (this.username == "") {
          this.$message({
            message: "用户名不能为空",
            type: "warning",
          });
        } else if (this.userpwd == "") {
          this.$message({
            message: "密码不能为空",
            type: "warning",
          });
        } else if (!tel.test(this.username)) {
          this.$message({
            message: "手机号码格式不正确",
            type: "warning",
          });
        } else {
          this.$message({
            message: "登录成功",
            type: "success",
          });
        }
        this.isloading = false;
      }, 1500);
    },
  },
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 10px;
}
.login_box {
  width: 75%;
  margin: 1.5rem auto;
}
</style>